GBML manual / Queues

queue_length

How many items target currently holds - 0 for an empty queue, up to target's own declared capacity once it is full.

Syntax

queue_length(target) -> int

Arguments

NameType
targetqueue

Returns

int

Description

How many items target currently holds - 0 for an empty queue, up to target's own declared capacity (/// @capacity, always a power of two - see queue_push - or 8 if untagged) once it is full.

This is how many items are IN target right now, not its capacity - a common use is checking whether there is still room before pushing, or showing a "3 enemies queued to spawn" count.

Example

/// @type {queue<int>}
/// @capacity 4
var turn_order = [1, 2, 3];
var waiting = queue_length(turn_order); // 3
A real capture - an empty queue, queue_length reading 0A real capture - an empty queue, queue_length reading 0
A real capture - an empty queue, queue_length reading 0
The same queue after filling it with the example's three turns - queue_length now 3The same queue after filling it with the example's three turns - queue_length now 3
The same queue after filling it with the example's three turns - queue_length now 3

On the GBA

Just the deque's size() - O(1), identical to stack_length/list_length.

See also: queue_pushqueue_popqueue_clearqueue_emptyData containers